/**
 * calculator
 *
 * @author : tzy
 * @Date : 2021-03-16
 * @Description:
 **/

package com.tang.calculator;

import com.tang.calculator.obj.TestObjLoan;
import com.tang.calculator.obj.TestObjPay;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import java.math.BigDecimal;
import java.util.*;

@SpringBootApplication
public class Main {
    public static void main(String[] args) throws Exception{
        ApplicationContext applicationContext = SpringApplication.run(Main.class, args);
//        Calculator calculator = applicationContext.getBean(ConfigCalculator.class);
        CalculateFactory calculator = applicationContext.getBean(CalculateFactory.class);



//        BigDecimal result = calculator.execute("((-10/6+5-1)*(-8)+(1*( 2- 3)+(7 / 8 -6 )+8- 6/ 4 - 5* 3 *( -2))) * 6+sum(1-3,2*2,(sum(1+1)+2)*3)");
//        BigDecimal result = calculator.execute("sum( sum( sum( sum( 1,2 , 3 , 4 , 5, 6 ),2 , 3 , 4 , 5, 6 ),2 , 3 , 4 , 5, 6 ),2 , 3 , 4 , 5, 6+1 ) + 2");
//        BigDecimal result = calculator.execute("-(sum(1, sum(1, 1+2)+sum(1, sum(1, 1+2)+2) / 2)) * 6");
//        BigDecimal result = calculator.execute("sum(1-3, 2*2, (sum(1+1)+2)*3)");
//        BigDecimal result = calculator.execute("sum(1-3, 2*2, 12)");
//        BigDecimal result = calculator.execute("(sum(1+1)+2)*3");

//        BigDecimal result = calculator.execute("case( '21'== strCat('2', 2), 1, 0)");
//        BigDecimal result = calculator.execute("('loan1'=='loan2') || ('loan1'=='loan2')");
//        BigDecimal result = calculator.execute("TestObjPay.payA*(TestObjPay.payB * 6 + TestObjPay.payC+ 5)");
//        System.out.println(result);

        TestObjLoan loan = new TestObjLoan().setId("loan1").setLoanA(new BigDecimal("10")).setLoanB(new BigDecimal("20"))
                .setLoanC(new BigDecimal("30")).setLoanD(new BigDecimal("40"));
        TestObjLoan loan1 = new TestObjLoan().setId("loan2").setLoanA(new BigDecimal("1")).setLoanB(new BigDecimal("2"))
                .setLoanC(new BigDecimal("3")).setLoanD(new BigDecimal("4"));
        TestObjPay pay = new TestObjPay().setLoanId("loan1").setPayA(new BigDecimal("1")).setPayB(new BigDecimal("2"));
        TestObjPay pay1 = new TestObjPay().setLoanId("loan2").setPayA(new BigDecimal("10")).setPayB(new BigDecimal("20"));
        Map<String, Object> resource = new HashMap<>();
        List<TestObjLoan> loanList = new LinkedList<>();
        List<TestObjPay> payList = new LinkedList<>();
        loanList.add(loan);
        loanList.add(loan1);
        payList.add(pay);
        payList.add(pay1);
        resource.put(pay.getClass().getSimpleName(), payList);
        resource.put(loan.getClass().getSimpleName(), loanList);

        Context context = calculator.createContext("exp_fundApply", "submit");
        context.setDataSource("mode","add",resource, TestObjPay.class);
        context.setDataSource("mode1","edit",resource, TestObjPay.class);
        context.setDataSource("mode","submit",resource, TestObjPay.class);
        context.run();
//        ((ConfigCalculator) calculator).executeConfig("/FormulaConfig.json", "exp", "submit", resource);


        System.out.println(pay);
        System.out.println(pay1);
    }
}

